import ejs from "ejs";
import fs from "fs";
import path from "path";
import { Log, LogStatus, LogType } from "../../util/Logger";

export class ExplorerService {
    constructor(private exportPath: string) {}

    configure(nodeUrl: string) {
        Log(LogType.Explorer, LogStatus.ToDo, `Configuring explorer...`);
        const template = fs.readFileSync(path.join(__dirname, "../template/explorer.env.ejs")).toString();
        const result = ejs.render(template, { nodeUrl });
        fs.writeFileSync(path.join(this.exportPath, "explorer.env"), result);
        fs.copyFileSync(
            path.join(__dirname, "../template/smart-contract-verifier.env"),
            path.join(this.exportPath, "smart-contract-verifier.env"),
        );
        Log(LogType.Explorer, LogStatus.Done, `Explorer configured`);
    }
}
